package org.jeecg.modules.demo3.fly.controller;

//import com.alibaba.dubbo.config.annotation.Reference;
//import com.zhuoyi.constant.MessageConstant;
//import com.zhuoyi.entity.Result;
//import com.zhuoyi.service.AccountService;
//import com.zhuoyi.utils.CosClientUtil;
//import com.zhuoyi.utils.CosClientUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.plaf.multi.MultiMenuItemUI;
import java.io.*;
import java.util.UUID;

@RestController
@RequestMapping("/load")
public class LoadAPPController {
//    @Reference
//    private AccountService accountService;
    @RequestMapping(value = "/OSAPP")
    public ResponseEntity<byte[]> downLoad(HttpServletRequest request) throws IOException {
        File file = new File("C:\\OS\\APP\\app-release.apk");
        byte[] body = null;
        InputStream is = new FileInputStream(file);
        body = new byte[is.available()];
        is.read(body);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "attchement;filename=" + file.getName());
        HttpStatus statusCode = HttpStatus.OK;
        ResponseEntity<byte[]> entity = new ResponseEntity<byte[]>(body, headers, statusCode);
        return entity;
    }
//    @RequestMapping(value = "/picture",method = RequestMethod.POST)
//    public Result downLoadPicture(@RequestParam("file") MultipartFile imgFile, Integer userId, HttpSession httpSession) throws IOException {
//        System.out.println(userId);
//        System.out.println(imgFile);
//        if (userId==null){
//            System.out.println("id是null");
//            return new Result(false,MessageConstant.PIC_UPLOAD_FAIL);
//        }else {
//            try {
//                //原始文件名
//                String originalFilename = imgFile.getOriginalFilename();
//                int lastIndexOf = originalFilename.lastIndexOf(".");
//                //后缀
//                String suffix = originalFilename.substring(lastIndexOf - 1);
//                //uuid获取名称
//                String fileName = UUID.randomUUID().toString() + suffix;
//                fileName="avatar/"+fileName;
//                CosClientUtils cosClientUtils = new CosClientUtils();
//                String name = cosClientUtils.uploadFile2Cos(imgFile,fileName);
//                String imgUrl = cosClientUtils.getImgUrl(fileName);
////                CosClientUtil cosClientUtil = new CosClientUtil();
////                String s = cosClientUtil.UPloadSOS(imgFile);
//                System.out.println(imgUrl);
//                accountService.editAvatar(userId,fileName);
////            //将上传图片名称存入Redis，基于Redis的Set集合存储
////            jedisPool.getResource().sadd(RedisConstant.SETMEAL_PIC_RESOURCES,fileName);
//                return new Result(true, MessageConstant.PIC_UPLOAD_SUCCESS,imgUrl);
//            } catch (Exception e) {
//                e.printStackTrace();
//                return new Result(false,MessageConstant.PIC_UPLOAD_FAIL);
//
//            }
//        }
//    }
}
